#!/bin/bash

############################################################################################
# ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
# Kernel Source:
# git clone https://github.com/Re4son/android_kernel_samsung-a5xelte.git -b nethunter-7.0
# ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
############################################################################################

##############################################
# Toolchains
##############################################

# Clang
unset CLANG_ROOT
unset CLANG_PATH
unset LD_LIBRARY_PATH
unset CLANG_TRIPLE
unset CC

# GCC 64bit
## arm64 cross compiler directory:
CCD64="${TD}/aarch64-standalone-4.9"
export CROSS_COMPILE=${CCD64}/bin/aarch64-linux-android-
## Source repository:
CROSS_COMPILE_SRC="https://images.kali.org/nethunter/toolchains/google_aarch64-standalone-oreo-4.9.tar.xz"
CROSS_COMPILE_SRC_TYPE="wget"

# GCC 32bit
## armhf cross compiler directory:
##CCD32="${TD}/armhf-standalone-4.9"
##export CROSS_COMPILE_ARM32=${CCD32}/bin/arm-linux-androideabi-
## Source repository:
##CROSS_COMPILE_ARM32_SRC="https://images.kali.org/nethunter/toolchains/google_armhf-standalone-4.9.tar.xz"
##CROSS_COMPILE_ARM32_TYPE="wget"

# Image Type (Only ONE of the following (lz4/gz) can be enabled!)
# GZ Image (Uncomment to Enable)
IMAGE_NAME=Image.gz

# Set to "true" to enable dtb
DO_DTB=true

# DTB Version
DTB_VER=1

# DTBTool
DTBTOOL=$BUILD_DIR/tools/dtbtool

# Space separated list of dtb file to generate
DTB_FILES="exynos7580-a5xelte_eur_open_00.dtb exynos7580-a5xelte_eur_open_01.dtb exynos7580-a5xelte_eur_open_02.dtb exynos7580-a5xelte_eur_open_03.dtb exynos7580-a5xelte_eur_open_08.dtb exynos7580-a5xelte_eur_open_09.dtb"

## The Samsung source doesn't like being compiled into a separate $OUT directory so we compile in the source directory

# Path to compiled kernel image
KERNEL_IMAGE=$KDIR/arch/arm64/boot/$IMAGE_NAME

# Input DTB path
DTB_IN=$KDIR/arch/arm64/boot/dts

# Location to build the kernel
KERNEL_OUT="$KDIR"

# Directory structure on the target device that will contain the modules directory
MODULE_DIRTREE=""

# Source Path for module tree to be copied to into nethunter zip
MODULES_IN=$BUILD_DIR/modules_out/lib/modules

# Kernel local name
export LOCALVERSION=-Re4son-1.0

